<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>健康干预
            <small>随访日记</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>健康干预</el-breadcrumb-item>
            <el-breadcrumb-item>随访日记</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="姓名/档案号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="visitdate" label="回访日期" align="center"></el-table-column>
                <el-table-column prop="client" label="被干预人" align="center"></el-table-column>
                <el-table-column prop="visitor" label="回访人员" align="center"></el-table-column>
                <el-table-column label="方式" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.visitway == '0' ? '见面' : scope.row.visitway == '1' ? '电话' : '微信'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="content" label="回访内容" align="center"></el-table-column>
                <el-table-column prop="feedback" label="反馈信息" align="center"></el-table-column>
                <el-table-column label="病人情况" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.patientcondition == '0' ? '未好转' :  '已好转'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="回访记录" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <template>
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="基本信息" name="first">
                                    <el-form label-position="right" label-width="100px">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="被干预人">
                                                    <el-input v-model="formData.client"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="档案号">
                                                    <el-input v-model="formData.fileNumber"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="回访人员">
                                                    <el-input v-model="formData.visitor"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="回访日期">
                                                    <el-date-picker type="date" placeholder="选择日期"
                                                                    v-model="formData.visitdate"
                                                                    value-format="yyyy-MM-dd HH:mm:ss"
                                                                    style="width: 100%;"></el-date-picker>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="回访方式">
                                                    <el-select v-model="formData.visitway">
                                                        <el-option label="见面" value="0"></el-option>
                                                        <el-option label="电话" value="1"></el-option>
                                                        <el-option label="微信" value="2"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="回访内容">
                                                    <el-input v-model="formData.content" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="反馈信息">
                                                    <el-input v-model="formData.feedback" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="病人情况">
                                                    <el-select v-model="formData.patientcondition">
                                                        <el-option label="未好转" value="0"></el-option>
                                                        <el-option label="已好转" value="1"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!--编辑弹窗-->
            <div class="edit-form">
                <el-dialog title="回访记录" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <template>
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="基本信息" name="first">
                                    <el-form label-position="right" label-width="100px">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="被干预人">
                                                    <el-input v-model="formData.client"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="档案号">
                                                    <el-input v-model="formData.fileNumber"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="回访人员">
                                                    <el-input v-model="formData.visitor"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="回访日期">
                                                    <el-date-picker type="date" placeholder="选择日期"
                                                                    v-model="formData.visitdate"
                                                                    value-format="yyyy-MM-dd HH:mm:ss"
                                                                    style="width: 100%;">
                                                    </el-date-picker>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="回访方式">
                                                    <el-select v-model="formData.visitway">
                                                        <el-option label="见面" value="0"></el-option>
                                                        <el-option label="电话" value="1"></el-option>
                                                        <el-option label="微信" value="2"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="回访内容">
                                                    <el-input v-model="formData.content" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="反馈信息">
                                                    <el-input v-model="formData.feedback" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="病人情况">
                                                    <el-select v-model="formData.patientcondition">
                                                        <el-option label="未好转" value="0"></el-option>
                                                        <el-option label="已好转" value="1"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>

    new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,
            rules: {//校验规则
                fileNumber: [{required: true, message: '档案号为必填项', trigger: 'blur'}],
                client: [{required: true, message: '被干预人为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //删除
            handleDelete(row){
                console.log(row.id);
                axios.post("/returnvisit/delete.do?id="+ row.id).then((res)=>{
                    if(res.data.flag){
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    }else {
                        this.$message.error(res.data.message);
                    }
                }).finally(()=>{
                    this.findPage();
                });
            },
            //弹出编辑框
            handleUpdate(row){
                this.formData = row;
                this.dialogFormVisible4Edit =true;
            },
            //编辑
            handleEdit() {

                this.$refs['dataEditForm'].validate((valid)=>{
                    if(valid){
                        axios.post("/returnvisit/edit.do", this.formData).then((res)=>{
                            if(res.data.flag){
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                });
                            }else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(()=>{
                            this.findPage();
                            this.dialogFormVisible4Edit = false;
                        });
                    }else {
                        this.$message.error("表单数据校验失败，请检查输入是否正确！");
                    }
                });
            },

            //添加
            handleAdd() {
                this.$refs['dataAddForm'].validate((valid)=>{
                    if(valid){
                        axios.post("/returnvisit/add.do", this.formData).then(() => {
                            if (res.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                });
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            this.findPage();
                            this.dialogFormVisible = false;
                        });
                    }else {
                        this.$message.error("表单数据校验失败，请检查输入是否正确！");
                    }
                });
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };

                //发送ajax请求，进行分页查询
                axios.post("/returnvisit/findByCondition.do", param).then((res) => {
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.imageUrl = null;
            },
            // 弹出添加窗口
            handleCreate() {
                //重置表单数据
                this.resetForm();
                this.dialogFormVisible = true;
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;//指定最新的页码
                this.findPage();
            }
        }
    });
</script>
</html>
